package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.coupons.domain.ticket.repository.IBatchBindRelationRepository;
import cc.lj.internal.coupons.infrastructure.dao.IBatchBindRelationMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.BatchBindRelationPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 电子券批次绑定关系表　mysql仓储实现
 * @author liangxifeng
 * @date 2022-06-12
 */
@Repository("batchBindRelationMysqlRespository")
public class BatchBindRelationMysqlRespository implements IBatchBindRelationRepository,BasePageHelper<BatchBindRelationPO> {
    @Autowired
    private IBatchBindRelationMapper mapper;
    @Override
    public List list(BatchBindRelationPO entityPO) {
        QueryWrapper<BatchBindRelationPO> wrapper = new QueryWrapper<>(entityPO);
        List<BatchBindRelationPO> entitys = mapper.selectList(wrapper);
        if(entitys == null)
        {
            throw new ServiceException(CoupousExceptionEnum.BATCH_BIND_RELATION_LIST_NULL);
        }
        return entitys;
    }

    @Override
    public BatchBindRelationPO getById(Integer id) {
        BatchBindRelationPO entityPO =  mapper.selectById(id);
        if(entityPO==null) {
            throw new ServiceException(CoupousExceptionEnum.BATCH_BIND_RELATION_ONE_IS_NULL);
        }
        return entityPO;
    }


    @Override
    public List<BatchBindRelationPO> getList(BatchBindRelationPO entityPO) {
        return this.list(entityPO);
    }

}
